<extend name="./Common/View/Public/base.html" />
<block name="main">
    <div class="layui-form layui-form-pane layui-tab-item layui-show">
        <form class="layui-form" method="post" action="" lay-filter="pageForm">
            <input type="hidden" name="project_id" value="{$projectId}">
            <div class="layui-form-item">
                <label for="user_id" class="layui-form-label">被评用户</label>
                <div class="layui-input-inline">
                    <select id="user_id" name="user_id" lay-filter="user">
                        <volist name="list" id="vo">
                            <option value="{$vo.user_id}" <if condition="$vo['user_id'] eq $userId">selected="selected"</if> >{$vo.name}</option>
                        </volist>
                    </select>
                </div>
            </div>
            {:W('Todo/Rate/show',array($projectId, $userId))}
            <div class="layui-form-item">
                <button class="layui-btn" key="set-mine" lay-filter="*" lay-submit="">确认提交</button>
            </div>
        </form>
    </div>
</block>
<block name="script">
    <script src="/api/sys/dict/format"></script>
    <script>
    layui.use(['table', 'form', 'layer', 'element', 'jquery'], function () {
        var table = layui.table
        , layer = layui.layer
        , form = layui.form
        ,element = layui.element;

        form.on('select(user)', function(data){
            window.location = "/space/rate/users/id/{$projectId}/user/"+data.value;
        });

        form.on('submit(pageForm)', function (data) {
            var flag=true;
            $('input[names=score]').each(function(){
                var $this = $(this);
                try{
                    var $val = parseFloat($this.val());
                    if($val < parseFloat($this.attr('min')) || $val > parseFloat($this.attr('max')) || $val > parseFloat($this.attr('score'))){
                        $this.val('').focus();
                        app.error('无效的分数,请检查您输入的数据!');
                        flag = false;
                        return false;
                    }
                }catch(e){
                    flag = false;
                    return false;
                }
            });
            if(!flag) return false;

            app.post('rate/score/saves', data.field, function (response) {
                if (response.error == '0') {
                    app.success(response.message);
                    window.location.reload(true);
                } else {
                    app.error(response.message);
                }
            });
            return false;
        });
    });
    </script>
</block>